//引入express包
const express = require('express')

//创建应用对象
const app = express();

//创建路由规则
app.get('/server', (request, response) => {
    //设置响应头，允许跨域
    response.setHeader('Access-Control-Allow-origin', '*')
    //设置响应体 只能是字符串和buffer
    const obj = {
        name: '111'
    }
    response.send(JSON.stringify(obj))

})
//创建路由规则
app.all('/server', (request, response) => {
    //设置响应头，允许跨域
    response.setHeader('Access-Control-Allow-origin', '*')
    //响应头
    response.setHeader('Access-Control-Allow-Headers', '*')
    //设置响应体 只能是字符串和buffer
    const obj = {
        name: '111'
    }
    response.send(JSON.stringify(obj))

})
//创建路由规则
app.all('/delay', (request, response) => {
    //设置响应头，允许跨域
    response.setHeader('Access-Control-Allow-origin', '*')
    //响应头
    response.setHeader('Access-Control-Allow-Headers', '*')
    //设置响应体 只能是字符串和buffer
    setTimeout(function() {
        const obj = {
            name: '111'
        }
        response.send(JSON.stringify(obj))
    }, 3000)
})
//监听服务
app.listen(8000, () => {
    console.log("服务启动中");
})